#include <btBulletCollisionCommon.h>
#include <btBulletDynamicsCommon.h>

#include "BulletState.h"
#include "Core.h"


using namespace pong;

void BulletState::load(Core& c) {
    // Build the broadphase
    broadphase = new btDbvtBroadphase;

    // Set up the collision configuration and dispatcher
    collisionConfig = new btDefaultCollisionConfiguration;
    dispatcher = new btCollisionDispatcher(collisionConfig);

    // The actual physics solver
    solver = new btSequentialImpulseConstraintSolver;

    // The world.
    world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver,
                                        collisionConfig);
}

void BulletState::unload(Core& c) {
    delete world;
    delete solver;
    delete dispatcher;
    delete collisionConfig;
    delete broadphase;
}

bool BulletState::update(Core& c) {
    world->stepSimulation(c.timeSinceLastUpdate(), 10);
    return true;
}
